

// import { BoxGeometry, Mesh, MeshStandardMaterial,TextureLoader,LineBasicMaterial,BufferGeometry,Line,Vector3} from "three"
import * as THREE from 'three';
export const ModelListConfig = []
const Require = (src) => {
  return require(`../assets/${src}`)
}
// const sky = new THREE.TextureLoader().load(Require('sky.jpg'))
// export const MeshModel = new THREE.Mesh(
//   new THREE.BoxGeometry(20, 20, 20),
//   new THREE.MeshStandardMaterial({
//     color: 'rgb(36, 172, 242)',
//     // roughness: 0 , 
//     // metalness: 0,
//     map: sky
//   })
// )
const curveArr = [
  0, 0, 0,
  350, 0, 0,
  0, 0, 350,
];
const curve = [];
for (let i = 0; i < curveArr.length; i += 3) {
  curve.push(new THREE.Vector3(curveArr[i], curveArr[i + 1], curveArr[i + 2]));
}
const RoutePoints = new THREE.CatmullRomCurve3(curve, true)
const sphereCurve = RoutePoints.clone()
export const pathPoints = sphereCurve.getPoints(200)
const RouteTexture = new THREE.TextureLoader().load(Require('run.png'))
const line = new THREE.Line(
  new THREE.BufferGeometry().setFromPoints(pathPoints),
  new THREE.LineBasicMaterial({
    color: "red",
    linewidth: 1,
  })
)
const addMesh = () => {
  let list = []
  for (let point of pathPoints) {
    const sphere = new THREE.BoxGeometry(3, 1, 1)
    const sphereMaterial = new THREE.MeshBasicMaterial({ map: RouteTexture })
    const sphereMesh = new THREE.Mesh(sphere, sphereMaterial)
    sphereMesh.position.set(point.x, point.y, point.z)
    ModelListConfig.push(sphereMesh)
    list.push(sphereMesh)
  }
  list.push(line)
  return list
}
// 加载轨道
export const LoadingTrack = () => {
  return addMesh()
}
// 创造地面
const texture = new THREE.TextureLoader().load(Require('R-C.jpg'))
export const Ground = new THREE.Mesh(new THREE.PlaneGeometry(300, 300), new THREE.MeshPhongMaterial({
  color: 0x888888, depthWrite: true,
  map: texture
}));
Ground.rotation.x = - Math.PI / 2;
Ground.receiveShadow = true;
ModelListConfig.push(Ground)  // 添加到模型数组
// const geometry = new ConeGeometry( 5, 20, 32 );
// const material = new MeshBasicMaterial( {color: 0xffff00} );
// const cone = new Mesh( geometry, material );
// MeshModel.name="MeshModel"//设置模型名称
/*
MeshModel.position.set(5, 5, 5)设置模型位置 (x,y,z)  or 
box.position.x = 5
box.position.y = 5
box.position.z = 5
*/
// 多人开发用来存储数据
// MeshModel.userData = {
//   name: 'MeshModel',
//   user: '我是Mesh方形模型'
// }